void  g(struct TreeNode* root, int targetSum, int sum, int* flag)
{
    if (root == NULL)
    {
        return;
    }
    if (root->left == root->right)
    {
        sum += root->val;
        if (sum == targetSum)
        {
            *flag = 0;
        }
        return;
    }
    sum += root->val;
    g(root->left, targetSum, sum, flag);
    g(root->right, targetSum, sum, flag);
}

bool hasPathSum(struct TreeNode* root, int targetSum) {
    if (root == NULL)
    {
        return false;
    }
    int sum = 0, flag = 1;
    g(root, targetSum, sum, &flag);

    if (flag == 1)
        return false;
    else
        return true;
}